package cn.nexd.location.collector.core;

import android.content.Context;

import cn.nexd.location.collector.NexdCollector;
import cn.nexd.location.collector.NexdCollectorConfig;

/**
 * Created by codingfish on 15/9/28.
 */
public abstract class WifiCollector extends Collector {

    private static final String ANDROID_PERMISSION_ACCESS_WIFI_STATE = "android.permission.ACCESS_WIFI_STATE";
    //    private static final String ANDROID_PERMISSION_WAKE_LOCK = "android.permission.ANDROID_PERMISSION_WAKE_LOCK";
    private static final String ANDROID_PERMISSION_CHANGE_WIFI_STATE = "android.permission.CHANGE_WIFI_STATE";
    protected WifiCollectorListener wifiCollectorListener;

    protected WifiCollector(Context context, NexdCollectorConfig collectorConfig) {
        super(context, collectorConfig);
    }

    public WifiCollector(Context context, NexdCollectorConfig collectorConfig, WifiCollectorListener wifiCollectorListener) {
        this(context, collectorConfig);
        this.wifiCollectorListener = wifiCollectorListener;
    }

    //    /* && checkPermission(ANDROID_PERMISSION_WAKE_LOCK)*/
    @Override
    protected boolean checkPermission() {
        boolean checkResult = checkPermission(ANDROID_PERMISSION_ACCESS_WIFI_STATE) && checkPermission(ANDROID_PERMISSION_CHANGE_WIFI_STATE);
        if (!checkResult) {
            wifiCollectorListener.onStop(getTaskId(), System.currentTimeMillis(), NexdCollector.COLLECTOR_TASK_STOP_TYPE_PERMISSION_UNAVAILABLE, NexdCollector.COLLECTOR_TASK_STOP_MESSAGE_PERMISSION_UNAVAILABLE + "( WIFI )");
        }
        return checkResult;
    }
}
